package com.csyaonie.kotlin

import java.lang.StringBuilder

fun main(){
    doSomething();
    TestKotlin.callStaticMethord();

    //标准函数 let with run apply
    val test=TestKotlin()
    test.doStudy(Student("090811437",6))

    val list= listOf("Apple","banana","Orange","Pear","Grape","Wartermelon");
    val builder = StringBuilder()
    for(fruit in list){
        builder.append(fruit).append("\n")
    }
    val res1=builder.append("all done").append("\n").toString()
    println(res1)
    println("==with==")
    val res2= with(StringBuilder()){
        for(fruit in list){
            append(fruit).append("\n")
        }
        append("all done").append("\n").toString()
    }
    println(res2)
    println("==run==")
    val res3= StringBuilder().run{
        for(fruit in list){
            append(fruit).append("\n")
        }
        append("all done").append("\n").toString()
    }
    println(res3)
    println("==apply==")
    val res4= StringBuilder().apply{
        for(fruit in list){
            append(fruit).append("\n")
        }
        append("all done").append("\n")
    }
    println(res4.toString())

}

class TestKotlin{

    fun doStudy(study:Study?){
        study?.let({ stu->
            stu.readBooks()
            stu.doHomework()
        })

        study?.let(){ stu->
            stu.readBooks()
            stu.doHomework()
        }

        study?.let {
            it.readBooks()
            it.doHomework()
        }
    }

    companion object{
        @JvmStatic
        fun callStaticMethord(){
            println(" This is a static methord")
        }
    }
}